﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using University.Workshop.Model;
using University.Workshop.DataAccess;

namespace University.Workshop.Business
{
    public static class TopicRegistrationManager
    {
        public static void RegisterTopic(String category, String text, String email)
        {
            if(String.IsNullOrEmpty(category) || String.IsNullOrEmpty(text) || String.IsNullOrEmpty(email))
            {
                throw new ValidationException("All fields are required");
            }
            String format = @"^[a-zA-Z1-9 !?()&]";
            if (text.Contains('>') || text.Contains('<') ||!Regex.IsMatch(text, format) )
            {
                throw new ValidationException("Invalid title");
            }
            Topic topic=new Topic();
            topic.Category = category;
            topic.CreationDate = DateTime.Now;
            topic.Points = 0;
            topic.Status = true;
            topic.Title = text;
            User user=UserDataAccess.GetUserByEmail(email);
            topic.UserId = user.Id;
            TopicDataAccess.InsertTopic(topic);
        }
    }
}
